<template>
	<view class="pages">
		<com-head textTit="搜索" :typeVal="1" :scrollTop="scrollTop"></com-head>
		
		<!-- 搜索 -->
		<view class="serchBox">
			<u-icon name="search" color="#999999" size="30"></u-icon>
			<input type="text"  @input="serchList()" v-model.trim="title" placeholder="搜索项目名称" placeholder-style="color:#999999"/>
		</view>
		
		
		<!-- 列表 -->
		 <!-- v-if="isHint" -->
		<view class="goods-box">
			<view v-for="item in list" class="goodsView" :key="item.id" @click="utlis.goUrl(`/pages/shop/projectInfo?peoject_id=${item.id}`)">
				<image class="goodsView__img" :src="item.pic[0]" mode="aspectFill"></image>
				<view class="goodsView__view">
					<view class="goodsView__view-name">{{item.name}}</view>
					<view class="goodsView__view-tags"><text v-for="row in item.tags">{{row.tags.name}}</text></view>
					<view class="goodsView__view-time">
						<image src="//jiudao123.oss-cn-shanghai.aliyuncs.com/store/img/shijian223.png"></image>
						{{item.duration||0}}分钟
					</view>
				</view>
			</view>
			<u-loadmore margin-top="40" margin-bottom="20" :status="status" :load-text="loadText"/>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadText: {
					loading: '努力加载中',
					nomore: '没有查询到更多了'
				},
				time: "",
				isHint:false,
				list:[],
				title:'',
				status:'loading',
				total:0,
				page:1,
				scrollTop: 0
			};
		},
		onPageScroll(e){
			this.scrollTop = e.scrollTop
		},
		onReachBottom() {
			if (this.total > this.list.length) {
				this.page++;
				this.getList();
			}
		},
		methods:{
			// 搜索商品
			serchList(){
				if(this.timer) {
					clearTimeout(this.timer);
				}
				this.timer = setTimeout(() => {
					this.getList()
				}, 800);
			},
			async getList(){
				if(this.title){
					let {data,code} = await this.$u.api.getProject({name:this.title,page:this.page,cate_id:0,store_id:this.store_id});
					if(code){
						if(this.page == 1 && !data.data.lenght){
							this.status = 'nomore';
						}
						this.list = [...this.list, ...data.data];
						this.list.forEach((ele)=>{
							ele.pic =ele.pic.split(',')
						})
						this.total = data.total;
						if (this.total <= this.list.length) this.status = 'nomore';
						else this.status = 'loading';
						this.isHint = true
					}
				}else{
					this.list = []
					this.isHint = false
					this.xin.Toast("商品名称不能为空！")
				}
			}
		}
	}
</script>

<style>
	page{
		background-color: #f6f7fa;
	}
</style>
<style lang="scss" scoped>
.pages{
	padding: 50rpx 30rpx;
	.serchBox{
		// width: 686rpx;
		height: 72rpx;
		background: rgba(255, 255, 255, 0.4);
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		padding:  0 26rpx;
		margin-bottom: 30rpx;
		box-shadow: 0px 2rpx 10rpx 0px rgba(0,0,0,0.07); 
		input{
			flex: 1;
			color: #333;
			font-size: 30rpx;
			margin-left: 22rpx;
			height: 100%;
		}
	}
	.goods-box{
		margin-top: 22rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #071529;
		border-radius: 8rpx;
		padding-bottom: 30rpx;
	}
	.goodsView{
		width: 686rpx;
		height: 174rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 24rpx;
		display: flex;
		margin-top: 24rpx;
		&__img{
			width: 126rpx;
			height: 126rpx;
			margin-right: 16rpx;
		}
		&__view{
			&-name{
				font-size: 28rpx;
				color: #1D2129;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
			&-tags{
				margin: 15rpx 0 16rpx 0;
				text{
					font-size: 16rpx;
					color: #E8C778;
					display: inline-block;
					width: 87rpx;
					height: 30rpx;
					border-radius: 4rpx 4rpx 4rpx 4rpx;
					border: 2rpx solid #E8C778;
					text-align: center;
					line-height: 30rpx;
					margin-right: 18rpx;
				}
			}
			&-time{
				width: 88rpx;
				height: 28rpx;
				background: linear-gradient( 134deg, #2D3039 0%, #495057 100%);
				border-radius: 4rpx 4rpx 4rpx 4rpx;
				font-size: 16rpx;
				color: #E8BC88;
				text-align: center;
				line-height: 28rpx;
				image{
					width: 16rpx;
					height: 16rpx;
					position: relative;
					top: 2rpx;
					margin-right: 5rpx;
				}
			}
		}
	}
}
</style>
